package com.xpgk.app.customer;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.annotation.Service;
import com.xpgk.mvc.base.BaseService;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.bentryRegister.CustomerDetail;
import com.xpgk.mvc.bentryRegister.CustomerProduct;
import com.xpgk.mvc.binShopService.CustomerService;
import com.xpgk.mvc.binShopService.ServicePartSize;
import com.xpgk.mvc.bloseWeight.DelWeiTarget;
import com.xpgk.mvc.measurement.TemporaryServices;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.productSet.Product;
import com.xpgk.mvc.statistic.dailyNursing.DailyNursingStatisticController;
import com.xpgk.mvc.statistic.dailyNursing.DailyNursingStatisticSQL;

@Service(name = AppCustomerInfoService.serviceName)
public class AppCustomerInfoService extends BaseService {

	private static final Log log = Log.getLog(AppCustomerInfoService.class);

	public static final String serviceName = "appCustomerInfoService";

	/**
	 * 保存顾客基本信息
	 * 
	 * @param customer
	 * @param customerDetail
	 */
	@Before(Tx.class)
	public void saveCustomerInfo(Customer customer, CustomerDetail customerDetail) {

		if (!customer.save()) {

		}

	}

	/**
	 * 获取测算结果
	 * 
	 * @param sex
	 * @param height
	 * @param age
	 * @param weight
	 * @return
	 */
	public static Record getTempResult(String sex, int height, int age, float weight) {
		float stdWeight = TemporaryServices.getStdWeight(sex, height, age);
		float delWeight = weight - stdWeight;
		int treatment = TemporaryServices.getTreatment(delWeight);
		return new Record().set("stdWeight", stdWeight).set("delWeight", delWeight).set("treatment", treatment);
	}

	public List<Record> getMentionOrgan(String xzqh) {
		String sql = getSqlMy(Organization.sqlId_findByXZQH);
		return Db.find(sql, xzqh);
	}
	
	public List<Record> getMentionOrganByAddress(String address) {
		String sql = getSqlMy(Organization.sqlId_findBySDXZ);
		return Db.find(sql, address);
	}
	
	public List<Record> getProduct(String customerIds) {
		String sql = getSqlMy(CustomerProduct.sqlId_selByCusIds);
		return Db.find(sql, customerIds);
	}
	
	public static Record getWeight(String customerIds) {
		String sql = getSqlMy(CustomerDetail.sqlId_selWeight);
		CustomerDetail customerDetail = CustomerDetail.dao.findFirst(sql,customerIds);
		String weight = customerDetail.getFloat(CustomerDetail.column_firstWeight)+"";
		String delWeight = customerDetail.getFloat(CustomerDetail.column_delWeight)+"";
		String nowWeight = customerDetail.getFloat(CustomerDetail.column_nowWeight)+"";
		return new Record().set("weight", weight)
				.set("delWeight",delWeight)
				.set("nowWeight", nowWeight);
		//return Db.find(sql, customerIds);
	}
	
	public static Record getInStore(String customerIds) {
		String sql = getSqlMy(DelWeiTarget.sqlId_selDelInShop);
		DelWeiTarget delWeiTarget = DelWeiTarget.dao.findFirst(sql,customerIds);
		String planToStoreNum = delWeiTarget.getInt(delWeiTarget.column_planToStoreNum)+"";	
		return new Record().set("planToStoreNum", planToStoreNum);
	
	}
	
	public static Record getTrueInStore(String customerIds,String customerIds1,String customerIds2) {
		String sql = getSqlMy(CustomerService.sqlId_selByCusDate);
		String trueToStoreNum = CustomerService.dao.findFirst(sql,customerIds,customerIds1,customerIds2).toString();
		return new Record().set("trueToStoreNum", trueToStoreNum);
	
	}
	

	 public List<Record> getGirth(String customerIds,String girth){
		 String sql = getSqlMy(ServicePartSize.sqlId_selByCusAndPartName);
		 return Db.find(sql, customerIds,girth);
		}
	 public List<Record> getWeightList(String customerIds){
		 String sql = getSqlMy(CustomerDetail.sqlId_selWeightList);
		 return Db.find(sql, customerIds);
		}
	 

}
